<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        border: 1px solid #ccc;
        margin-right: 5px;
      }
    </style>
  </head>
  <body>
    <script>
      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        ctx.beginPath();
        ctx.fillStyle = '#f00';
        ctx.fillRect(50,50,200,200);

        ctx.globalCompositeOperation = 'lighter';

        ctx.beginPath();
        ctx.fillStyle = '#0f0';
        ctx.fillRect(150,150,200,200);

      })();

      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        const img1 = new Image();
        img1.src = '../imgs/05.png';
        img1.onload = function(){
          ctx.drawImage(img1,200-img1.width/2,200-img1.height/2);

          
        ctx.globalCompositeOperation = 'multiply'
        } 


        const img2 = new Image();
        img2.src = '../imgs/04.png';
        img2.onload = function(){
          ctx.drawImage(img2,200-img2.width/2,200-img2.height/2);
        }

      })();

      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        const img1 = new Image();
        img1.src = '../imgs/05.png';
        img1.onload = function(){
          ctx.drawImage(img1,200-img1.width/2,200-img1.height/2);

          
        ctx.globalCompositeOperation = 'screen'
        } 


        const img2 = new Image();
        img2.src = '../imgs/04.png';
        img2.onload = function(){
          ctx.drawImage(img2,200-img2.width/2,200-img2.height/2);
        }

      })();

      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        const img1 = new Image();
        img1.src = '../imgs/05.png';
        img1.onload = function(){
          ctx.drawImage(img1,200-img1.width/2,200-img1.height/2);

          
        ctx.globalCompositeOperation = 'darken'
        } 


        const img2 = new Image();
        img2.src = '../imgs/04.png';
        img2.onload = function(){
          ctx.drawImage(img2,200-img2.width/2,200-img2.height/2);
        }

      })();

      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 400;
        canvas.height = 400;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        const img1 = new Image();
        img1.src = '../imgs/05.png';
        img1.onload = function(){
          ctx.drawImage(img1,200-img1.width/2,200-img1.height/2);

          
        ctx.globalCompositeOperation = 'lighten'
        } 


        const img2 = new Image();
        img2.src = '../imgs/04.png';
        img2.onload = function(){
          ctx.drawImage(img2,200-img2.width/2,200-img2.height/2);
        }

      })();
      
    </script>
  </body>
</html>
